﻿namespace ST.Simulator.Trans
{
    public class TcpReqData
    {
        public ushort transactionId { get; set; }
        public ushort protocolId { get; set; }
        public ushort length { get; set; }
        public ushort unitId { get; set; }
        public ushort functionCode { get; set; }

        public ushort StartAddress { get; set; }

        public ushort ReqNum { get; set; }

        public TcpReqData(byte[] data)
        {
            // 解析事务标识符
              transactionId = (ushort)((data[0] << 8) | data[1]);

            // 解析协议标识符
              protocolId = (ushort)((data[2] << 8) | data[3]);

            // 解析长度
            length = (ushort)((data[4] << 8) | data[5]);

            // 解析单元标识符
              unitId = data[6];

            // 解析功能码
              functionCode = data[7];
            if (data.Length >= 12)
            {
                StartAddress=protocolId = (ushort)((data[8] << 8) | data[9]);
                ReqNum = protocolId = (ushort)((data[10] << 8) | data[11]);
            }
        }



    }
}
